2374. 边积分最高的节点
为保证权益,题目请参考 2374. 边积分最高的节点(From LeetCode).
解决方案1
Python
python
from typing import List
class Solution:
def edgeScore(self, edges: List[int]) -> int:
max_node_id = -1
max_node_num = -1
bian_ji_fen = [0] * len(edges)
for i, edge in enumerate(edges):
bian_ji_fen[edge] += i
for i, b in enumerate(bian_ji_fen):
if b > max_node_num:
max_node_id = i
max_node_num = b
return max_node_id
if __name__ == "__main__":
so = Solution()
# assert so.edgeScore([1,0,0,0,0,7,7,5]) == 7
# assert so.edgeScore([2,0,0,2]) == 0
print(so.edgeScore([2, 0, 0, 2]))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27